// pages/sys/sys.js
const common = require('../../../../public.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },
 
    scan() {
        wx.scanCode({
            success: (res) => {
                const result = res.result
                //1. 扫码支付
                if (result && result.indexOf('/pay/scanForPay') != -1) {
                    const quary = result.split('?')[1]
                    wx.navigateTo({
                        url: '/pages/scanForPay/index?' + quary + '&name=lanling',
                    })
                } else {
                    common.showToast('暂不支持当前功能~')
                    setTimeout(function() {
                        wx.navigateTo({
                            url: '/pages/Dj/index',
                          })
                     }, 1000);
                }
            },
            fail: (res) => {
                if (res.errMse != 'scanCode:fail cancel') {
                    common.showToast('扫码失败')
                }
                wx.navigateTo({
                  url: '/pages/Dj/index',
                })
            }
        })
    },

  
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that =this
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that. scan()
            }else{
                wx.navigateTo({
                  url: '/pages/login/index',
                })
            }
        })
    
    },


})